package com.huluobo.high3demo.video;

import android.app.Application;

import androidx.annotation.NonNull;
import androidx.lifecycle.MutableLiveData;

import com.google.gson.Gson;
import com.huluobo.mvvm.baen.BannerBeanResult;
import com.huluobo.mvvm.baen.CommentBeanResult;
import com.huluobo.mvvm.baen.FollowLikeBeanResult;
import com.huluobo.mvvm.baen.VideoBeanResult;
import com.huluobo.mvvm.net.Constant;
import com.huluobo.mvvm.viewmodel.BaseViewModel;

import java.util.HashMap;
import java.util.Map;

import okhttp3.MediaType;
import okhttp3.RequestBody;

/**
 * Created by LC on 2023/9/15.
 */
public class VideoViewModel extends BaseViewModel<VideoRepo> {

    MutableLiveData<VideoBeanResult> success = new MutableLiveData<>();
    MutableLiveData<String> failed = new MutableLiveData<>();

    MutableLiveData<BannerBeanResult> bannerSuccess = new MutableLiveData<>();

    MutableLiveData<String> bannerFailed = new MutableLiveData<>();

    MutableLiveData<FollowLikeBeanResult> likeSuccess = new MutableLiveData<>();
    MutableLiveData<String> likeFailed = new MutableLiveData<>();

    MutableLiveData<FollowLikeBeanResult> noLikeSuccess = new MutableLiveData<>();
    MutableLiveData<String> noLikeFailed = new MutableLiveData<>();

    MutableLiveData<FollowLikeBeanResult> followAuthSuccess = new MutableLiveData<>();
    MutableLiveData<String> followAuthFailed = new MutableLiveData<>();

    MutableLiveData<CommentBeanResult> sendCommentSuccess = new MutableLiveData<>();

    MutableLiveData<String> sendCommentFailed = new MutableLiveData<>();

    MutableLiveData<CommentBeanResult> getCommentSuccess = new MutableLiveData<>();

    MutableLiveData<String> getCommentFailed = new MutableLiveData<>();


    public VideoViewModel(@NonNull Application application) {
        super(application);
    }

    public void getVideoList(int currentPage, int pageSize) {
        repo.getVideoList(currentPage, pageSize, success, failed);
    }

    public void getBanner() {
        repo.getBanner(bannerSuccess, bannerFailed);
    }

    public void likeVideo(int videoId) {
        repo.likeVideo(videoId, likeSuccess, likeFailed);
    }

    public void noLikeVideo(int videoId) {
        repo.noLikeVideo(videoId, noLikeSuccess, noLikeFailed);
    }

    public void followAuth(String authName) {
        repo.followAuth(authName, followAuthSuccess, followAuthFailed);
    }

    public void sendComment(String msg, int videoId) {
        //封装参数
        Map<String, Object> map = new HashMap<>();
        map.put(Constant.PARAM_MSG, msg);//键值对形式
        map.put(Constant.PARAM_VIDEO_ID, videoId);

        String json = new Gson().toJson(map);//把map转化为一个json
        RequestBody body = RequestBody.create(MediaType.parse("application/json;charset=utf-8"), json);//把json转换为一个body
        repo.sendComment(body, sendCommentSuccess, sendCommentFailed);
    }

    public void getCommentList(int videoId) {
        repo.getCommentList(videoId, getCommentSuccess, getCommentFailed);
    }

    @Override
    protected VideoRepo createRepo() {
        return new VideoRepo();
    }
}
